#include <QCoreApplication>
#include <QDebug>
#include <QStringList>
#include <QString>

typedef qint32 doubleword;
typedef qint8 byte;

#define  WORD_LLO(xxx)  ((byte) ((doubleword)  (xxx) & 255 ))//分离32位数宏定义
#define  WORD_LHI(xxx)  ((byte) ((doubleword)  (xxx) >> 8  ))
#define  WORD_HLO(xxx)  ((byte) ((doubleword)  (xxx) >>16  ))
#define  WORD_HHI(xxx)  ((byte) ((doubleword)  (xxx) >>24  ))

#define  MAX(x, y)  ( ((x) > (y)) ? (x) : (y) )//比较大小宏定义
#define  MIN(x, y)  ( ((x) < (y)) ? (x) : (y) )


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qint32 i=0x12345678;//待执行的32位数
    qint32 newnum;//定义新组成的32位数
        qDebug().nospace()<<"原始值:0x"<<hex<<i<<"=="<<dec<<i;

        qDebug().nospace()<<"0x"<<hex<<WORD_HHI(i)<<"=="<<dec<<WORD_HHI(i)
                      <<"; 0x"<<hex<<WORD_HLO(i)<<"=="<<dec<<WORD_HLO(i)
                      <<"; 0x"<<hex<<WORD_LHI(i)<<"=="<<dec<<WORD_LHI(i)
                      <<"; 0x"<<hex<<WORD_LLO(i)<<"=="<<dec<<WORD_LLO(i);
        //将32位数据按每8位拆分

    QList<qint8> values;//创建链表存储数据
        qDebug().nospace()<<"最高8位和次高8位最大值："<<"0x"<<hex<<MAX(WORD_HHI(i),WORD_HLO(i))<<"("<<dec<<MAX(WORD_HHI(i),WORD_HLO(i))<<")"<<endl
                          <<"次低8位和最低8位最小值："<<"0x"<<hex<<MIN(WORD_LHI(i),WORD_LLO(i))<<"("<<dec<<MIN(WORD_LHI(i),WORD_LLO(i))<<")";

    newnum=WORD_HLO(i)+(WORD_LLO(i)<<8)+(WORD_HHI(i)<<16)+(WORD_LHI(i)<<24);
        qDebug().nospace()<<"重新组合后的数值："<<"0x"<<hex<<newnum<<"("<<dec<<newnum<<")";

    values<<WORD_HHI(i)<<WORD_HLO(i)<<WORD_LHI(i)<<WORD_LLO(i);
        qDebug()<<"排序前："<<values;//输出链表里原序列的数据


    std::sort(values.begin(),values.end(),std::greater<qint8>());//对链表内数按照排序并输出
        qDebug()<<"排序后："<<values;


    return a.exec();
}
